#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/fcntl.h>
#include <sys/stat.h>

int main(int argc, char **argv)
{
	int fd = open("/tmp/tmmap", O_RDWR);
	struct stat st;
	fstat(fd, &st);

	void *maddr = mmap(NULL, 5, PROT_WRITE, MAP_PRIVATE, fd, 0);
	if (maddr == MAP_FAILED) {
		perror("mmap");
		_exit(EXIT_SUCCESS);
	}
	char *ptr = maddr;

	if (argc > 1) {
		snprintf(ptr, 1024, "%s", argv[argc - 1]);
	} else {
		printf("%s\n", ptr);
	}
	pause();
	return 0;
}